package com.example.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.example.model.HomeServiceItemDTO;

@Mapper
public interface ConCategoryServiceMapper {
    @Select("select serviceId from con_category_service where categoryId = #{categoryId}")
    List<Integer> getServiceListByCategoryId(@Param("categoryId") Integer categoryId);

    @Insert("insert into con_category_service(categoryId, serviceId) values(#{categoryId}, #{serviceId})")
    int addCategoryService(@Param("categoryId") Integer categoryId, @Param("serviceId") Integer serviceId);

    @Delete("delete from con_category_service where serviceId = #{serviceId}")
    int deleteCategoryServiceByServiceId(@Param("serviceId") Integer serviceId);

    @Select("SELECT s.id as serviceId, s.serviceName, s.pic, MIN(u.price) AS lowestPrice " +
            "FROM con_category_service ccs " +
            "JOIN tb_service s ON s.id = ccs.serviceId " +
            "JOIN con_employee_service ces ON ces.serviceId = s.id " +
            "JOIN tb_user u ON u.id = ces.userId " +
            "WHERE ccs.categoryId = #{categoryId} " +
            "GROUP BY s.id " +
            "ORDER BY s.id DESC " +
            "LIMIT 3")
    List<HomeServiceItemDTO> getHomeServiceListByCategoryId(@Param("categoryId") Integer categoryId);
}
